#include <iostream>
#include "Modules/Utilities/htmlgenerator.h"
#include "Modules/Utilities/classroomfilereader.h"
#include "Modules/Utilities/subjectfilereader.h"
#include "Modules/Utilities/groupfilereader.h"

int main(int argc, char *argv[]){

    if(argc != 4){
        std::cout << "format is \"Class Scheduler.exe\" [subjectfile path] [groupfile path] [classroomfile path]" << std::endl;
        return 0;
    }
    try{
        SubjectFileReader::SubjectList sList = SubjectFileReader::read(argv[1]);
        try{
            GroupFileReader::StudentGroupList list = GroupFileReader::read(argv[2], sList);
            try{
                Scheduler::ClassroomList list2 = ClassroomFileReader::read(argv[3]);

                std::cout << "Starting scheduling algorithm.. Please wait.." << std::endl;
                clock_t start = clock();
                GraphBuilder::SessionList sessions = Scheduler::schedule(list, list2.size());
                clock_t final = clock() - start;
                std::cout << "Scheduling done.. Duration : " << static_cast<double>(final)/ static_cast<double>(CLOCKS_PER_SEC) << "second(s)"<<std::endl;
                std::cout << "Assigning classsrooms.. Please wait..." << std::endl;
                start = clock();
                Scheduler::CompleteSessionList cSessions = Scheduler::assignClassroom(sessions, list2);
                final = clock() - start;
                std::cout << "Classroom assignment done.. Duration : " << static_cast<double>(final)/ static_cast<double>(CLOCKS_PER_SEC) << "second(s)"<<std::endl;
                HtmlGenerator::generate(cSessions, list2);
            } catch(const char *e){
                std::cout << e << std::endl;
                return -1;
            }
        } catch(const char *e){
            std::cout << e << std::endl;
            return -1;
        }
    } catch(const char *e){
        std::cout << e << std::endl;
        return -1;
    }
    return 0;
}
